POST Mission Message doc

James Peret 10 年之前
父节点
当前提交
033404297c

+ 52 - 2
app/data/page-list.json

@@ -77,9 +77,12 @@
77 77
         "title" : "Mission Details",
78 78
         "endpoint" : {
79 79
           "type" : "GET",
80
-          "base" : "/missions/:slug"
80
+          "base" : "/missions/:slug",
81
+          "object1" : "/missions/",
82
+          "id1"     : "slug",
83
+          "object2" : ""
81 84
         },
82
-        "implemented" : false,
85
+        "implemented" : true,
83 86
         "description" : "Returns detailed information about a mission, including lists of all agents, all tasks and recent activity.",
84 87
         "variables" : [
85 88
           {
@@ -109,6 +112,7 @@
109 112
           "type" : "POST",
110 113
           "base" : "/missions"
111 114
         },
115
+        "implemented" : true,
112 116
         "description" : "Creates a new mission on the system and returns it back. A user token is needed for this request.",
113 117
         "variables" : [
114 118
           {
@@ -142,6 +146,52 @@
142 146
         }
143 147
       },
144 148
       {
149
+        "pageUrl" : "/rest-api-v1/get-mission-messages",
150
+        "slug"  : "get-mission-messages",
151
+        "title" : "Mission Messages",
152
+        "endpoint" : {
153
+          "type"    : "GET",
154
+          "base"    : "/missions/:slug/messages",
155
+          "object1" : "/missions/",
156
+          "id1"     : "slug",
157
+          "object2" : "/messages"
158
+        },
159
+        "implemented" : true,
160
+        "description" : "Returns a list of chat messages from a mission. By default, messages are ordered by date starting by the newest ones.",
161
+        "variables" : [
162
+          {
163
+            "name" : "slug",
164
+            "description" : "A shortname without spaces used as the mission identifier and url. This needs to be unique.",
165
+            "variable_type" : "string"
166
+          }
167
+        ]
168
+      },
169
+      {
170
+        "pageUrl" : "/rest-api-v1/post-mission-message",
171
+        "slug"  : "post-mission-message",
172
+        "title" : "Send Message",
173
+        "endpoint" : {
174
+          "type"    : "POST",
175
+          "base"    : "/missions/:slug/message/",
176
+          "object1" : "/missions/",
177
+          "id1"     : "slug",
178
+          "object2" : "/messages"
179
+        },
180
+        "implemented" : true,
181
+        "description" : "Creates a new message on the selected mission and broadcasts it to all mission agents.",
182
+        "variables" : [
183
+          {
184
+            "name" : "slug",
185
+            "description" : "A shortname without spaces used as the mission identifier and url. This needs to be unique.",
186
+            "variable_type" : "string"
187
+          },{
188
+            "name" : "content",
189
+            "description" : "Text string containing the message.",
190
+            "variable_type" : "string"
191
+          }
192
+        ]
193
+      },
194
+      {
145 195
         "pageUrl" : "/rest-api-v1/get-mission-agents",
146 196
         "slug"  : "get-mission-agents",
147 197
         "title" : "Mission Agent List",

+ 31 - 7
app/scripts/controllers/rest-api-v1-ctrl.js

@@ -59,11 +59,13 @@ angular.module('avalancheDocsApp')
59 59
     DataService.getResponse()
60 60
 
61 61
     // API Calls
62
-    $scope.getData = function(url){
62
+    $scope.getData = function(endpoint){
63
+      var url = $scope.fullURL(endpoint);
63 64
       usSpinnerService.spin('spinner-1');
64 65
       DataService.get(url, $scope.processInputs(), $scope.tokens.selectedToken);
65 66
     }
66
-    $scope.postData = function(url){
67
+    $scope.postData = function(endpoint){
68
+      var url = $scope.fullURL(endpoint);
67 69
       usSpinnerService.spin('spinner-1');
68 70
       DataService.post(url, $scope.processInputs(), $scope.data, $scope.tokens.selectedToken);
69 71
     }
@@ -71,8 +73,10 @@ angular.module('avalancheDocsApp')
71 73
     $scope.processInputs = function(){
72 74
       var inputs = [];
73 75
       for (var i = 0; i < $scope.pageData.variables.length; i++) {
74
-        var field = $scope.pageData.variables[i].name;
75
-        inputs[field] = $scope.pageData.variables[i].value;
76
+        if($scope.pageData.variables[i].name != $scope.pageData.endpoint.id1){
77
+          var field = $scope.pageData.variables[i].name;
78
+          inputs[field] = $scope.pageData.variables[i].value;
79
+        }
76 80
       }
77 81
       return inputs;
78 82
     }
@@ -108,8 +112,22 @@ angular.module('avalancheDocsApp')
108 112
 
109 113
     // Misc Functions
110 114
 
111
-    $scope.fullURL = function(url){
112
-      return "http://localhost:5000/api" + url;
115
+    $scope.fullURL = function(endpoint){
116
+      if(endpoint.object1 == undefined){
117
+        return "http://localhost:5000/api" + endpoint.base;
118
+      } else {
119
+        var id1_value = ""
120
+        for (var i = 0; i < $scope.pageData.variables.length; i++) {
121
+          if($scope.pageData.variables[i].name == endpoint.id1){
122
+            id1_value = $scope.pageData.variables[i].value
123
+          }
124
+        }
125
+        if(id1_value == undefined || id1_value == ""){
126
+          id1_value = ":" + endpoint.id1;
127
+        }
128
+        return "http://localhost:5000/api" + endpoint.object1 + id1_value + endpoint.object2;
129
+      }
130
+
113 131
     }
114 132
 
115 133
     $scope.status = function(code) {
@@ -125,10 +143,16 @@ angular.module('avalancheDocsApp')
125 143
           info: "The request has been fulfilled and resulted in a new resource being created."
126 144
         };
127 145
       }
146
+      if(code == 302){
147
+        return {
148
+          code : "302 Found",
149
+          info: "The resource you are requesting has redirected you to another resource."
150
+        };
151
+      }
128 152
       if(code == 401){
129 153
         return {
130 154
           code : "401 Unauthorized",
131
-          info: ""
155
+          info: "The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)."
132 156
         };
133 157
       }
134 158
       if(code == 422){

+ 2 - 2
app/scripts/services/data-service.js

@@ -8,7 +8,7 @@ angular.module('avalancheDocsApp')
8 8
     console.log(inputs);
9 9
     $http({
10 10
       method: 'GET',
11
-      url: 'http://localhost:5000/api' + url,
11
+      url: url,
12 12
       headers: { 'Authorization' : "Bearer " + token },
13 13
       params: inputs
14 14
     }).then(function(data, status, headers, config) {
@@ -37,7 +37,7 @@ angular.module('avalancheDocsApp')
37 37
     console.log(inputs);
38 38
     $http({
39 39
       method: 'POST',
40
-      url: 'http://localhost:5000/api' + url,
40
+      url: url,
41 41
       headers: { 'Authorization' : "Bearer " + token },
42 42
       params: inputs
43 43
     }).then(function(data, status, headers, config) {

+ 5 - 3
app/views/helpers/api-endpoint-field.html

@@ -2,13 +2,15 @@
2 2
   <div class="col-sm-9">
3 3
     <fieldset class="form-group">
4 4
       <label for="exampleInputEmail1">API Endpoint</label>
5
-      <input type="text" class="form-control" id="endpoint" placeholder="{{fullURL(pageData.endpoint.base)}}" disabled>
5
+      <input type="text" class="form-control" id="endpoint" placeholder="{{fullURL(pageData.endpoint)}}" disabled>
6 6
     </fieldset>
7 7
   </div>
8 8
   <div class="col-sm-3">
9
-    <fieldset class="form-group" style="margin-top: 35px;">
10
-      <button type="submit" class="btn btn-success btn-sm" ng-click="getData(pageData.endpoint.base)">Test</button>
9
+    <fieldset class="form-group" style="margin-top: 35px; margin-leg: -4px;">
10
+      <button ng-show="pageData.endpoint.type == 'GET'" type="submit" class="btn btn-success btn-sm" ng-click="getData(pageData.endpoint)">GET</button>
11
+      <button ng-show="pageData.endpoint.type == 'POST'" type="submit" class="btn btn-info btn-sm" ng-click="postData(pageData.endpoint)">POST</button>
11 12
       <button type="submit" class="btn btn-sm" ng-click="hideResponse()" ng-hide="hideResult">Hide</button>
12 13
     </fieldset>
13 14
   </div>
14 15
 </div>
16
+<p>{{pageData.variables.slug.value}}</p>

+ 1 - 1
app/views/rest-api-v1.html

@@ -29,7 +29,7 @@
29 29
         <ng-include src="'views/helpers/under-construction.html'" ng-hide="pageData.implemented"></ng-include>
30 30
 
31 31
         <div ng-if="pageData.variables.length > 0">
32
-          <h5 class="top-spacer">Variables</h5>
32
+          <h5 class="top-spacer">Parameters</h5>
33 33
           <table class="table table-bordered top-spacer">
34 34
             <tr ng-repeat="variable in pageData.variables">
35 35
               <th>{{variable.name}}</th>